package com.ruoyi.web.controller.agoniapp;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.UserIdByRequest;
import com.ruoyi.system.service.IAgoniFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/agoniapp/favorite")
public class FavoriteController {
    @Autowired
    private IAgoniFavoriteService favoriteService;


    //TODO:是否收藏
    @GetMapping("/isFavorite/{productId}")
    public AjaxResult isFavorite(@PathVariable("productId") Long productId, HttpServletRequest request) {
        //TODO:获取用户id
        Long userId= UserIdByRequest.getUserId(request);

        Boolean isFavorite=favoriteService.isFavorite(userId,productId);

        return AjaxResult.success("查询成功",isFavorite);
    }


    //TODO:收藏
    @PostMapping("/addFavorite/{productId}")
    public AjaxResult addFavorite(@PathVariable("productId") Long productId, HttpServletRequest request) {
        //TODO:获取用户id
        Long userId= UserIdByRequest.getUserId(request);

      Boolean result=  favoriteService.addFavorite(userId,productId);
        return AjaxResult.success("收藏成功",result);
    }


}
